package districting;

import java.util.*;
import com.vividsolutions.jts.triangulate.VoronoiDiagramBuilder;
import com.vividsolutions.jts.geom.*;
import com.vividsolutions.jts.geom.PrecisionModel;

public class Voronoi {

   private VoronoiDiagramBuilder myVor;

   private Collection<Coordinate> sites;

   public Voronoi() {
      myVor = new VoronoiDiagramBuilder();
      sites = new ArrayList<Coordinate>();
   }

   public void addPoint(Coordinate coord) {
      sites.add(coord);
   }

   public Geometry generateVoronoi(double minLong, double maxLong, double minLat,
         double maxLat) {
      Envelope bound = new Envelope(minLong, maxLong, minLat, maxLat);

      myVor.setClipEnvelope(bound);
      myVor.setSites(sites);
      return myVor.getDiagram(new GeometryFactory(new PrecisionModel(), 4326));
   }
}
